﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;

public class UIPointerEventListener : MonoBehaviour, IEventSystemHandler, IPointerDownHandler, IPointerUpHandler
{
    private PointerEventData holdData;
    public Action<PointerEventData> onPointerDown;
    public Action<PointerEventData> onPointerHold;
    public Action<PointerEventData> onPointerUp;

    public void OnPointerDown(PointerEventData data)
    {
        if (this.onPointerDown != null)
        {
            this.onPointerDown(data);
        }
        this.holdData = data;
    }

    public void OnPointerUp(PointerEventData data)
    {
        if (this.onPointerUp != null)
        {
            this.onPointerUp(data);
        }
        this.holdData = null;
    }

    private void Update()
    {
        if ((this.holdData != null) && (this.onPointerHold != null))
        {
            this.onPointerHold(this.holdData);
        }
    }
}

